﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CPPEI.Coolzon.Designer.Views
{
    [ValueConversion(typeof(NodeType), typeof(Uri))]
    public class NodeTypeToImage : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Uri ret;
            NodeType nodeType = (NodeType)value;
            switch (nodeType)
            {
                case NodeType.Solution:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeTypeIcon/Solution.ico");
                    break;
                case NodeType.Scene:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeTypeIcon/Scene.ico");
                    break;
                case NodeType.Folder:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeTypeIcon/Folder.ico");
                    break;
                case NodeType.Template:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeTypeIcon/Resource.ico");
                    break;
                case NodeType.Resource:
                default:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeTypeIcon/Resource.ico");
                    break;
            }

            return ret;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            NodeType nodeType = default(NodeType);
            Uri uri = (Uri)value;
            if (uri.AbsoluteUri.IndexOf("Solution") >= 0)
            {
                nodeType = NodeType.Solution;
            }
            else if (uri.AbsoluteUri.IndexOf("Scene") >= 0)
            {
                nodeType = NodeType.Scene;
            }
            else if (uri.AbsoluteUri.IndexOf("Folder") >= 0)
            {
                nodeType = NodeType.Folder;
            }
            else if (uri.AbsoluteUri.IndexOf("Template") >= 0)
            {
                nodeType = NodeType.Template;
            }
            else
            {
                nodeType = NodeType.Resource;
            }
            return nodeType;
        }
    }
}
